package ThirtiethDay;

public class Rob {
    public int rob(int[] nums) {
        if (nums.length == 1){
            return nums[0];
        }
        if (nums.length == 2){
            return Math.max(nums[0], nums[1]);
        }
        int roba = nums[0], robb = nums[1], robc = Math.max(robb,roba + nums[2]);
        for (int i = 3; i < nums.length; i++) {
            int tempa = robb, tempb = robc;
            int maxa = Math.max(roba + nums[i],robb + nums[i]);
            robc = Math.max(robc, maxa);
            robb = tempb;
            roba = tempa;
        }
        return robc;
    }
}
